﻿using System;
using System.Windows;
using System.Windows.Media;


namespace advadev.Windows.Graph
{
    /// <summary>
    /// Represents a layer element container
    /// </summary>
    internal class LayerElementContainer : DependencyObject
    {

        /// <summary>
        /// Initializes a new instance of the LayerElementContainer class by
        /// the given parameter
        /// </summary>
        /// <param name="layerElement">
        /// Layer element
        /// </param>
        /// <param name="margin">
        /// Margin
        /// </param>
        internal LayerElementContainer(FrameworkElement layerElement, Thickness margin)
        {
            LayerElement = layerElement;
            Margin = margin;
            Height = layerElement.ActualHeight;
            Width = layerElement.ActualWidth;
            VisualBrush = new VisualBrush(layerElement) { Stretch = Stretch.None, AlignmentX = AlignmentX.Left, AlignmentY = AlignmentY.Top };
            layerElement.SizeChanged += new SizeChangedEventHandler((object sender, SizeChangedEventArgs args) =>
            {
                Height = layerElement.ActualHeight;
                Width = layerElement.ActualWidth;
            });
        }


        #region dependency properties
        static internal readonly DependencyProperty LayerElementProperty = DependencyProperty.Register("LayerElement", typeof(FrameworkElement), typeof(LayerElementContainer), new UIPropertyMetadata(null));
        internal FrameworkElement LayerElement
        {
            get { return (FrameworkElement)GetValue(LayerElementProperty); }
            set { SetValue(LayerElementProperty, value); }
        }

        static internal readonly DependencyProperty MarginProperty = DependencyProperty.Register("Margin", typeof(Thickness), typeof(LayerElementContainer), new UIPropertyMetadata(new Thickness(0d, 0d, 0d, 0d)));
        internal Thickness Margin
        {
            get { return (Thickness)GetValue(MarginProperty); }
            set { SetValue(MarginProperty, value); }
        }

        static internal readonly DependencyProperty HeightProperty = DependencyProperty.Register("Height", typeof(double), typeof(LayerElementContainer), new UIPropertyMetadata(0d));
        internal double Height
        {
            get { return (double)GetValue(HeightProperty); }
            set { SetValue(HeightProperty, value); }
        }

        static internal readonly DependencyProperty WidthProperty = DependencyProperty.Register("Width", typeof(double), typeof(LayerElementContainer), new UIPropertyMetadata(0d));
        internal double Width
        {
            get { return (double)GetValue(WidthProperty); }
            set { SetValue(WidthProperty, value); }
        }

        static internal readonly DependencyProperty VisualBrushProperty = DependencyProperty.Register("VisualBrush", typeof(Brush), typeof(LayerElementContainer), new UIPropertyMetadata(null));
        internal Brush VisualBrush
        {
            get { return (Brush)GetValue(VisualBrushProperty); }
            set { SetValue(VisualBrushProperty, value); }
        }
        #endregion dependency properties

    }

}
